﻿using System;
using DKE_Kinect.Entwicklung.Core;
using Microsoft.Xna.Framework;

namespace DKE_Kinect.Entwicklung.Kinect.GestureEvents
{
    /// <summary>
    /// Klasse, die Gesten des Rechten Arms bereitstellt
    /// </summary>
    public class RightArmGestures : GestureEvent
    {
        /// <summary>
        /// Konstruktor für Gesten des rechten Arms
        /// </summary>
        public RightArmGestures()
        {
        }

        /// <summary>
        /// Initialisiert RightArm-Gesten
        /// </summary>
        /// <param name="RightShoulder">Rechte Schulter</param>
        /// <param name="RightElbow">Rechter Ellenbogen</param>
        /// <param name="RightHand">Rechte Hand</param>
        public void LookFor(Vector3 RightShoulder, Vector3 RightElbow, Vector3 RightHand)
        {
            double RightArmRangeX = (Math.Max(Math.Max(RightShoulder.X, RightElbow.X), RightHand.X) - (Math.Min(Math.Min(RightShoulder.X, RightElbow.X), RightHand.X)));
            double RightArmRangeY = (Math.Max(Math.Max(RightShoulder.Y, RightElbow.Y), RightHand.Y) - (Math.Min(Math.Min(RightShoulder.Y, RightElbow.Y), RightHand.Y)));
            double RightArmRangeZ = ((Math.Max(Math.Max(RightShoulder.Z, RightElbow.Z), RightHand.Z) - (Math.Min(Math.Min(RightShoulder.Z, RightElbow.Z), RightHand.Z))));
            double RightArmRange = (RightArmRangeX + RightArmRangeY + RightArmRangeZ) / 3;


            // Right Hand up (--> Rechte Hand geht über Schulterhöhe)
            if (RightArmRangeX <= RightArmRange && RightHand.Y < RightShoulder.Y && RightElbow.Y > RightShoulder.Y && RightArmRangeY >= RightArmRange)
            {
                //EVENT
                OnGestureEvent(new GestureEventArgs(Gestures.RightHandUp, StateManager.CurrMode));
                return;
            }

            // Right Arm out (--> Rechter Arm ausgestreckt)
            if (RightArmRangeY <= RightArmRange && RightHand.X > RightShoulder.X && RightArmRangeZ <= RightArmRange && RightArmRangeX >= RightArmRange*2)
            {
                //EVENT
                OnGestureEvent(new GestureEventArgs(Gestures.RightArmOut, StateManager.CurrMode));
                return;
            }

            // Right Arm forward (--> Rechter Arm nach vorn gestreckt)
            if (RightArmRangeX <= RightArmRange && RightHand.Z < RightShoulder.Z && RightArmRangeY <= RightArmRange && RightArmRangeZ >= RightArmRange*2)
            {
                //EVENT
                OnGestureEvent(new GestureEventArgs(Gestures.RightArmForward, StateManager.CurrMode));
                return;
            }

            // Right Arm up (--> Rechter Arm nach oben gestreckt)
            if (RightArmRangeX <= RightArmRange && RightHand.Y < RightShoulder.Y && RightElbow.Y < RightShoulder.Y && RightArmRangeZ <= RightArmRange)
            {
                //EVENT
                OnGestureEvent(new GestureEventArgs(Gestures.RightArmUp, StateManager.CurrMode));
                return;
            }

        }

    }
}
